
require(zTree)

zTT1= zTreeTables("August2Expansionpath2021.xls")
subjects1=zTT1$subjects

zTT2= zTreeTables("September21ExpansionPath2021.xls")
subjects2=zTT2$subjects
subjects2$Subject=subjects2$Subject+100

zTT3= zTreeTables("September 29ExpansionPath2021.xls")
subjects3=zTT3$subjects
subjects3$Subject=subjects3$Subject+200

zTT4= zTreeTables("October13expansionpath2021.xls")
subjects4=zTT4$subjects
subjects4$Subject=subjects4$Subject+300

subjects=rbind(subjects1,subjects2,subjects3,subjects4)

#Clean data
subjects$responder=(subjects$"response1[50]">0)
subjects=subset(subjects,responder>0)

uidlist=unique(subjects$Subject)

#create a frame with observations
obsframe=data.frame(uid=vector('numeric'),block=vector('numeric'), incentive=vector('numeric'), number=vector('numeric'), state=vector('numeric'), response=vector('numeric'),react=vector('numeric'))
for(i in 1:length(uidlist)){
playframe=subjects[i,]
uidplace=uidlist[i]

#block 1
for (j in 1:50){
blockplace=1
incentiveplace=incentivec[playframe[1,683]]
numberplace=j
stateplace=playframe[1,(736+j)]
responseplace=playframe[1,(72+j)]
reactplace=playframe[1,(122+j)]
addframe=data.frame(uid=uidplace,block=blockplace, incentive=incentiveplace, number=numberplace, state=stateplace, response=responseplace,react=reactplace)
obsframe=rbind(obsframe,addframe)
}

#block 2
for (j in 1:50){i
blockplace=2
incentiveplace=incentivec[playframe[1,684]]
numberplace=j
stateplace=playframe[1,(786+j)]
responseplace=playframe[1,(222+j)]
reactplace=playframe[1,(272+j)]
addframe=data.frame(uid=uidplace,block=blockplace, incentive=incentiveplace, number=numberplace, state=stateplace, response=responseplace,react=reactplace)
obsframe=rbind(obsframe,addframe)

}

}



#define correctness
obsframe$correct=(obsframe$state==obsframe$response)

#mean correctness
correct5=sum(obsframe$correct*(obsframe$incentive==5))/sum(obsframe$incentive==5)
correct95=sum(obsframe$correct*(obsframe$incentive==95))/sum(obsframe$incentive==95)
correctness=c(correct5,correct95)

obsframe5=subset(obsframe,incentive==5)
obsframe95=subset(obsframe,incentive==95)

#change terminology to work with older scripts
expframe=obsframe

expframe$incentive5=(expframe$incentive==5)
expframe$incentive95=(expframe$incentive==95)

expframe$Bresponse <-expframe$response==2
expframe$Bstate <- expframe$state==2
expframe$Aresponse <-expframe$response==1
expframe$Astate <- expframe$state==1

